<?php
class Point_model extends MY_Model
{
    private $table = 'blues_point_carousel';
    public function __construct()
    {
        parent::__construct();
    }
    public function get_carousel_by_id($id)
    {
        $this->db->where("id",$id);
        $query=$this->db->get($this->table);
        return $query->row_array();
    }
   
    public function get_point_carousel_list()
    {
        $where = "";
		$sql = "SELECT * FROM blues_point_carousel {$where}";
		$query = $this->db->query($sql);
        return $query->result_array();        
    }

   
    public function add($data)
    {
        $res= $this->db->insert($this->table,$data);
        if($res){
            return $this->db->insert_id();
        }
        return FALSE;
    }

    
    public function edit($id,$data)
    {
        $this->db->where('id',$id);
        return $this->db->update($this->table,$data);
    }        
    //删除分类
    public function del($del_ids)
    {
		$sql = "DELETE FROM blues_point_carousel WHERE id in ({$del_ids})";
		$query = $this->db->query($sql);
        return true;
    }

    public function addAnswerPoints($data = array()){
        //插入
        $res = $this->db->insert("blues_member_points",$data);
		$this->totalPoint($data['AccountID'],$data['points']);
        return $res;
    }
	
	public function totalPoint($AccountID,$toplus = 0){
		$sql = "SELECT points  FROM blues_user WHERE AccountID = '".$AccountID."' ";
		$query = $this->db->query($sql);
        $result =$query->row_array();
	
		$this->db->where(["AccountID"=>$AccountID]);
		$total = $result['points']+$toplus;
		$res = $this->db->update("blues_user",['points'=>$total]);
		return $res;
	}
    
    public function addAnswerMoney($data = array()){
        //插入
        $res = $this->db->insert("blues_member_money",$data);
        return $res;
    }

    public function getSendPoints($newsID)
    {
        $sql = "SELECT
                    sum(points) cnt
                FROM
                    blues_member_points points
                    
                WHERE
                    type = 6
                AND typeid in (SELECT questionID FROM blues_question WHERE newsID = {$newsID})";
        $query = $this->db->query($sql);
        return $query->row_array()['cnt'];
    }

    public function getSendMoney($newsID)
    {
        $sql = "SELECT
                    sum(money) cnt
                FROM
                    blues_member_money money
                    
                WHERE
                    type = 6
                AND typeid in (SELECT questionID FROM blues_question WHERE newsID = {$newsID})";
        $query = $this->db->query($sql);
        return $query->row_array()['cnt'];
    }
}

/* End of file flybird/orders_model.php */
/* Location: ./application/models/orders_model.php */